﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Photography.Admin
{
    public partial class AdminMaster : System.Web.UI.MasterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        public int? AdminID
        {
            get
            {
                return Session["AdminID"] == null ? (int?)null : (int?)Session["AdminID"];
            }
            set
            {
                Session["AdminID"] = value;
            }
        }

        public string AdminName { get { return Session["AdminName"] == null ? null : Session["AdminName"].ToString(); } set { Session["AdminName"] = value; } }
        public string AdminEmail { get { return Session["AdminEmail"] == null ? null : Session["AdminEmail"].ToString(); } set { Session["AdminEmail"] = value; } }
        public int CategoryId { get { return string.IsNullOrEmpty(Request["cat"]) ? 0 : int.Parse(Request["cat"]); } }
        public int? GalleryId { get { return string.IsNullOrEmpty(Request["gal"]) ? (int?)null : int.Parse(Request["gal"]); } }
        public int? PhotoId { get { return string.IsNullOrEmpty(Request["p"]) ? (int?)null : int.Parse(Request["p"]); } }

        public void RedirectToManageGalleries(int categoryId)
        {
            Response.Redirect(string.Format("ManageGalleries.aspx?cat={0}", categoryId));
        }

        public void RedirectToManageGalleries()
        {
            if (GalleryId.HasValue)
                Response.Redirect(string.Format("ManageGalleries.aspx?cat={0}&gal={1}", CategoryId, GalleryId));
            else
                Response.Redirect(string.Format("ManageGalleries.aspx?cat={0}", CategoryId));
        }

        public void RedirectToGallery(bool noGallery = false)
        {
            if (noGallery)
                Response.Redirect(string.Format("Gallery.aspx?cat={0}", CategoryId));
            else if (GalleryId.HasValue)
                Response.Redirect(string.Format("Gallery.aspx?cat={0}&gal={1}", CategoryId, GalleryId));
            else
                throw new ApplicationException("Gallery not specified");
        }

        public void RedirectToPhoto()
        {
            if (!GalleryId.HasValue)
                throw new ApplicationException("Gallery not specified");

            Response.Redirect(string.Format("Photo.aspx?cat={0}&gal={1}", CategoryId, GalleryId));
        }

        public void RedirectToPhoto(int photoId)
        {
            if (!GalleryId.HasValue)
                throw new ApplicationException("Gallery not specified");

            Response.Redirect(string.Format("Photo.aspx?cat={0}&gal={1}&p={2}", CategoryId, GalleryId, photoId));
        }
    }
}